Skip to content

fix(ai): normalize tool-result image data URLs - #1421

Open
Altairpaca wants to merge 2 commits into
code-yeongyu:mainfrom
Altairpaca:fix/1260-tool-result-image-data-url
Open

fix(ai): normalize tool-result image data URLs#1421
Altairpaca wants to merge 2 commits into
code-yeongyu:mainfrom
Altairpaca:fix/1260-tool-result-image-data-url

Conversation

@Altairpaca

@Altairpaca Altairpaca commented Sep 7, 2026

Copy link
Copy Markdown

Summary

Fixes #1260 by restoring the ImageContent.data contract at the shared message-normalization boundary before provider serialization.

Tool results occasionally contain an already-prefixed data:<mime>;base64,... string even though ImageContent.data is defined as raw base64. Responses adapters then add their own prefix and produce an invalid double-prefixed image_url.

Root cause

transformMessages() normalized unsupported media and tool-call IDs but passed supported tool-result image payloads through unchanged. Provider adapters therefore had to trust that ImageContent.data was raw base64, and an already-prefixed value leaked into the Responses serializer.

Changes

  • Normalize tool-result media blocks in transform-messages.ts.
  • If data starts with the exact canonical prefix for its declared MIME type (data:${mimeType};base64,), strip that prefix and keep raw base64 internally.
  • Leave ordinary raw base64 byte-identical.
  • Do not accept/normalize arbitrary or mismatched data: payloads.
  • Add deterministic regression coverage for raw base64 and already-prefixed image data through convertResponsesMessages().

Scope / risk

The change is limited to tool-result media normalization. User attachments are unchanged. Provider serializers retain their existing raw-base64 contract and continue adding the wire prefix themselves.

Validation

A focused converter regression is included and the branch is based directly on current upstream main (5a23f6edfa628f5d1a86422f683742e092feebc2). Repository CI is expected to exercise the package test/typecheck and changelog gates.

Closes #1260


Summary by cubic

Fixes tool-result images with already-prefixed data URLs getting double-prefixed in Responses serializers, producing invalid image_url values. Now strips the canonical data:<mime>;base64, prefix from tool-result image data before provider serialization so only one prefix gets added.

Written for commit 9b082b4. Summary will update on new commits.

Review in cubic

Copy link
Copy Markdown
Author

Implementation is ready for review. The branch is current-main based and the diff is limited to the shared tool-result normalization seam plus the focused #1260 regression. All three fork workflows are currently action_required with no jobs executed; when convenient, please approve the workflow run. I’ll own any CI/review follow-up through merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tool-result image data URLs are double-prefixed for Codex Responses, producing invalid image_url

1 participant